package com.knife.oauth.api.controller.v1;

import com.knife.common.utils.Results;
import com.knife.interfaces.annotations.KnifeInterfaceLog;
import com.knife.interfaces.constants.KnifeInterfaceCodeEnum;
import com.knife.oauth.app.service.LoginService;
import com.knife.oauth.domain.entity.IamUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author tianhao.luo@hand-china.com
 * @version 1.0
 * @date 2022年04月16日 星期六 5:54 下午
 * @description
 * @since 1.0
 */
@RestController("v1.LoginController")
@RequestMapping("/v1/user")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    //@KnifeInterfaceLog(interfaceEnum = KnifeInterfaceCodeEnum.LOGIN)
    public ResponseEntity<String> login(@RequestBody IamUser iamUser) {
        return Results.success(loginService.login(iamUser));
    }

    @GetMapping("/info")
    @KnifeInterfaceLog(interfaceEnum = KnifeInterfaceCodeEnum.USER_INFO)
    public ResponseEntity<IamUser> userInfo(){
        return Results.success(loginService.selectUserInfo());
    }

    @PostMapping("/loginOut")
    @KnifeInterfaceLog(interfaceEnum = KnifeInterfaceCodeEnum.LOGIN_OUT)
    public ResponseEntity<Boolean> loginOut(HttpServletRequest httpServletRequest){
        loginService.loginOut(httpServletRequest);
        return Results.success(true);
    }
}
